﻿namespace DeltaGroup.WheelOfJeopardy.UI.ViewModel
{
    using System;

    using DeltaGroup.WheelOfJeopardy.Model;

    public sealed class SectorInfo
    {
        #region Fields

        private const string RESOURCE_PATH_PATTERN = "/DeltaGroup.WheelOfJeopardy;component/UI/Resources/{0}.xaml";

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SectorInfo"/> class.
        /// </summary>
        /// <param name="sector">The sector.</param>
        public SectorInfo(Sector sector)
        {
            Sector = sector;
            Title = sector.Caption;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SectorInfo"/> class.
        /// </summary>
        /// <param name="sector">The sector.</param>
        /// <param name="keyVariation">The key variation.</param>
        public SectorInfo(Sector sector, string keyVariation)
            : this(sector)
        {
            KeyVariation = keyVariation;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets or sets the arc angle.
        /// </summary>
        /// <value>The arc angle.</value>
        public double ArcAngle
        {
            get; internal set;
        }

        /// <summary>
        /// Gets or sets the end angle.
        /// </summary>
        /// <value>The end angle.</value>
        public double EndAngle
        {
            get; internal set;
        }

        /// <summary>
        /// Gets the resource path.
        /// </summary>
        /// <value>The resource path.</value>
        public string ResourcePath
        {
            get {
                string path;
                if (Sector==null) {
                    path = FormatResourcePath("DefaultSector");
                }
                else if (Sector.GetType() == typeof(CategorySector))
                {
                    path = FormatResourcePath(Sector.GetType(),KeyVariation);
                }
                else
                {
                    path = FormatResourcePath(Sector.GetType());
                }

                return path;
            }
        }

        /// <summary>
        /// Gets or sets the sector scale.
        /// </summary>
        /// <value>The scale.</value>
        public double Scale
        {
            get; internal set;
        }

        /// <summary>
        /// Gets or sets the sector.
        /// </summary>
        /// <value>The sector.</value>
        public Sector Sector
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the start angle.
        /// </summary>
        /// <value>The start angle.</value>
        public double StartAngle
        {
            get; internal set;
        }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string Title
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the key variation.
        /// </summary>
        /// <value>The key variation.</value>
        private string KeyVariation
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Formats the resource path.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private string FormatResourcePath(string name)
        {
            return string.Format(RESOURCE_PATH_PATTERN, name);
        }

        /// <summary>
        /// Formats the resource path.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        private string FormatResourcePath(Type type, string variation = "")
        {
            string name = type.Name + variation;
            return FormatResourcePath(name);
        }

        #endregion Methods
    }
}